<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isShow">
        <span @click="$emit('deleteAllHistory')">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isShow = true" />
    </van-cell>

    <van-cell
      :title="item"
      v-for="(item, index) in history"
      :key="index"
      @click="controlHistory(index,item)"
    >
      <van-icon name="close" v-show="isShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",
  components: {},
  props: ["history"],
  data() {
    return {
      isShow: false,
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    controlHistory(index,item) {
      if (this.isShow) {
        // 删除
        this.history.splice(index, 1);
      } else {
        // 点击跳转
        console.log(item)
        this.$emit("search",item);
      }
    },
  },
};
</script>

<style scoped lang="less"></style>